package main

import (
	"context"
	"fmt"

	v1 "gitee.com/lcc_dr/restful-api-demo/api/book/v1"
	"google.golang.org/grpc"
)

func main() {
	ctx := context.Background()

	// credential := middleware.NewGrpcAuther()
	// credential.WithPerRPCCredentials("admin", "1234")
	grpcConn, err := grpc.DialContext(ctx, "127.0.0.1:18050", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}

	grpcClient := v1.NewServiceClient(grpcConn)
	//
	// md := middleware.ClientCredentialsHeader("admin", "1234")
	// metactx := metadata.NewOutgoingContext(ctx, md)
	// CallOption := grpc.Header(header)
	// replay, err := grpcClient.Hello(metactx, &api.Request{Value: "world"})

	req := &v1.CreateBookRequest{
		CreateBy: "lcc",
		Author:   "zhangsan",
		Name:     "three king2",
	}
	replay, err := grpcClient.CreateBook(ctx, req)
	if err != nil {
		panic(err)
	}

	fmt.Println(replay)

}
